import 'package:flutter/material.dart';
import 'package:x3_base_core/x3_base_core.dart';
import 'package:flutter_scankit/flutter_scankit.dart';

mixin BaseScanState<T extends StatefulWidget> on State<T> {

  FlutterScankit _scanKit;

  @override
  void initState() {
    this._scanKit = new FlutterScankit();
    this._scanKit.addResultListen( ( dynamic value ) => this.listenScanResult( value ) );
    super.initState();
  }

  Future<void> startScan() async {
    bool requirePermission = await BasePermissionUtils.handlerRequirePermission();
    if ( requirePermission == false ) return;
    await this._scanKit.startScan(scanTypes: [ScanTypes.ALL]);
  }

  void listenScanResult( String value );

}
